/*lic*/
#ifndef __FSM_BASE_H__
#define __FSM_BASE_H__

#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>

#include "sc_map.h"

typedef long fsm_err_t;
typedef fsm_err_t (*CallbackFunc)(void);

typedef struct __TAG_Fsm_Ctrl_Def {
	char name[32];
	uint32_t fsm_status; // 状态，注意，状态回调优先级越高，越早被调用
	uint32_t fsm_action_call; // 状态机任务生效
	uint32_t fsm_status_mask[32]; // 状态机掩码。当所有状态都为1时对应的函数才会被执行。
	
	CallbackFunc action[32]; // 状态机执行函数
	
	// 初始化
	fsm_err_t (*Init_Fsm)(struct __TAG_Fsm_Ctrl_Def* obj, char* name);
	// 注册action
	fsm_err_t (*Register_Action)(struct __TAG_Fsm_Ctrl_Def* obj, uint8_t action_id, uint32_t mask, CallbackFunc action_callback);
	// 删除action
	fsm_err_t (*Deregister_Action)(struct __TAG_Fsm_Ctrl_Def* obj, uint8_t action_id);
	// 执行指定的action
	fsm_err_t (*Active_Action)(struct __TAG_Fsm_Ctrl_Def* obj, uint8_t action_id);
	// 设置指定的状态。
	fsm_err_t (*Active_Status)(struct __TAG_Fsm_Ctrl_Def* obj, uint8_t action_id, bool run_now);
	// 空闲处理函数
	fsm_err_t (*Idle_action)(struct __TAG_Fsm_Ctrl_Def* obj);
	
}Fsm_Ctrl_Def;

fsm_err_t Init_Fsm_Interface(Fsm_Ctrl_Def* obj, char* name);



extern struct sc_map_fsm fsm_list;

#endif /* __FSM_BASE_H__ */

/*eof*/

